package com.estronger.shopmanage.ui.aftermarket;

import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.estronger.shopmanage.R;
import com.estronger.shopmanage.base.BaseActivity;
import com.estronger.shopmanage.base.MyApplication;
import com.estronger.shopmanage.manager.NetManager;
import com.estronger.shopmanage.ui.aftermarket.bean.AftermarketDetailBean;
import com.estronger.shopmanage.ui.aftermarket.bean.AftermarketItem;
import com.estronger.shopmanage.ui.aftermarket.views.GoodsView;
import com.estronger.shopmanage.ui.aftermarket.views.MediaView;
import com.google.gson.Gson;
import com.lidroid.xutils.http.RequestParams;

import java.util.ArrayList;
import java.util.List;

public class AppointmentDetailActivity extends BaseActivity {

    @BindView(R.id.detail_scroller)
    ScrollView scrollView;
    @BindView(R.id.tvfButton)
    TextView tvfButton;//抢单

    @BindView(R.id.build_item_name)
    TextView itemName;
    @BindView(R.id.build_item_phone)
    TextView phoneText;
    @BindView(R.id.build_phone_call)
    ImageView callImage;//电话图片
    @BindView(R.id.build_send_sms)
    ImageView smsImage;//短信图片

    @BindView(R.id.cts_name_contener)
    LinearLayout ctsLayout;//头部，cts
    @BindView(R.id.cts_name_text)
    TextView ctNameText;
    @BindView(R.id.cts_name)
    TextView ctsName;

    @BindView(R.id.build_item_location)
    TextView locationIcon;
    @BindView(R.id.build_detail_appointment)
    TextView appointment;

    @BindView(R.id.task_type)
    TextView taskTypeText;//派工类型
    @BindView(R.id.appointment_dec)
    TextView appointmentDes;

    @BindView(R.id.build_remark)
    TextView remarkTextView;//备注

    @BindView(R.id.com_remark_container)
    LinearLayout completedRemarkContainer;
    @BindView(R.id.completed_remark)
    TextView completText;

    @BindView(R.id.image_view)
    MediaView mediaView;

    @BindView(R.id.goods_view)
    GoodsView goodsView;

    @BindView(R.id.below_goods_view)
    View belowView;
    @BindView(R.id.oderNum)
    TextView orderNumText;

    Gson gson = new Gson();
    AftermarketItem detainInfoBean;

    @Override
    protected void initView() {
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = View.inflate(this, R.layout.activity_appointment_detail_layout,null);
        setContentView(view);
        ButterKnife.bind(this,view);

        requstData();
    }

    void requstData(){
        String dlvid = getIntent().getStringExtra("dlvid");
        RequestParams params = new RequestParams();
        params.addBodyParameter("sf_action", "claimgettaskdetail");
        params.addBodyParameter("usercode", MyApplication.getUserCode());
        params.addBodyParameter("taskid", dlvid);
        showDialog("获取售后派工详情中",true);
        Log.e(NetManager.AFTERMARKET_DETAIL + "---------",dlvid);
        connect(params, NetManager.AFTERMARKET_DETAIL);
    }

    @Override
    protected void onNetSuccess(int code, String result) {
        dimssDialog();
        if (code == NetManager.AFTERMARKET_DETAIL){
            Log.e(NetManager.AFTERMARKET_DETAIL + "---------",result);
            AftermarketDetailBean detailBean = gson.fromJson(result,AftermarketDetailBean.class);
            detainInfoBean = detailBean.getData();
            onBindData(detainInfoBean);
        }
    }

    @Override
    protected void onNetErorr(int code, String msg) {
        dimssDialog();
    }

    //显示字段
    void onBindData(AftermarketItem infoBean){
        if (TextUtils.isEmpty(infoBean.getFcstbuildname())) {
            itemName.setText(infoBean.getFcstname());
        } else {
            itemName.setText(infoBean.getFcstbuildname() + "-"
                    + infoBean.getFcstname());
        }
        taskTypeText.setText(infoBean.getFtypedesc());
        ctNameText.setText(infoBean.getFcstname());
        phoneText.setText(infoBean.getFcstmobile());
        locationIcon.setText(infoBean.getFaddress());
        appointment.setText("预约时间:" + infoBean.getFplantime());
        appointmentDes.setText(infoBean.getFplandesc());
        remarkTextView.setText(infoBean.getFcmtcontent());
        completedRemarkContainer.setVisibility(TextUtils.isEmpty(infoBean.getFfinishdesc())?View.GONE:View.VISIBLE);
        completText.setText(infoBean.getFfinishdesc());
        orderNumText.setText(infoBean.getFclaimwono());

        mediaView.setWoattachImages(detainInfoBean.getWoattach());
        mediaView.setImageDatasource(detainInfoBean.getImgitem());
        goodsView.setDataArray(detainInfoBean.getOrditem());


    }
}
